﻿Public Class About
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBoxMisID.Text = ReturnMisiuneID()
        TextBoxUserID.Text = ReturnUserNr()
    End Sub

    Protected Sub Button_Cautare_Click(sender As Object, e As EventArgs) Handles Button_Cautare.Click
        LabelMSG.Visible = False
        DetailsView1.DataBind()
    End Sub

    Protected Sub DetailsView1_DataBound(sender As Object, e As EventArgs) Handles DetailsView1.DataBound
        If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
            DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
        End If
        If DetailsView1.Rows(1).Cells(1).Text.Trim() = ReturnMisiuneID().ToString Or DetailsView1.Rows(1).Cells(1).Text.Length = 0 Or DetailsView1.Rows(1).Cells(1).Text.Length = 6 Then
            DetailsView1.Rows(0).Enabled = True
        Else
            DetailsView1.Rows(0).Enabled = False
        End If
    End Sub


    Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)


    End Sub

    Protected Sub DetailsView1_ItemDeleting(ByVal sender As Object, ByVal e As DetailsViewDeleteEventArgs)

        If Calendar1.SelectedDate < "01.01.1900" Then
            'UserMsgBox(Me, "Selectati data juramantului (din calendar)!")
            LabelMSG.Text = "Selectați data jurământului (din calendar)!"
            LabelMSG.Visible = True
            e.Cancel = True
        Else            
            If DetailsView1.Rows(2).Cells(1).Text.Length = 6 Or DetailsView1.Rows(2).Cells(1).Text.Length = 0 Then
                'Select Case MsgBox("Persoana va fi programată! Confirmați?", MsgBoxStyle.YesNo, Title = "Juramant")
                'Case MsgBoxResult.No
                'e.Cancel = True
                'End Select
            Else
                'Select Case MsgBox("Persoana este deja programată! Doriți să o reprogramați?", MsgBoxStyle.YesNo, Title = "Juramant")
                '   Case MsgBoxResult.No
                ' e.Cancel = True
                '    Case MsgBoxResult.Yes
                SqlDataSource1.DeleteCommand = "UPDATE CetatenieFULL SET DataDepJur = @DataDepJuramant WHERE (ID = @ID)"
                ' End Select
            End If
            End If
    End Sub

    Protected Sub DetailsView1_ItemDeleted(Sender As Object, e As DetailsViewDeletedEventArgs)
        DetailsView1.DataBind()

    End Sub

    Public Function ReturnMisiuneID() As Integer

        Dim misIDadapter As New eServicii.DataSetJURAMANTTableAdapters.aspnet_UsersTableAdapter
        Dim MisiuneID As Integer
        Dim NumeUser As String
        If HttpContext.Current.Request.IsAuthenticated Then
            NumeUser = Membership.GetUser().UserName()
            'NumeUser = HttpContext.Current.User.Identity.Name
            MisiuneID = misIDadapter.GetDataMisID(NumeUser).Rows(0).Item("MisiuneID")
            Return MisiuneID
        Else
            Return 0
        End If
    End Function

    Public Function ReturnUserNr() As Integer
        Dim misIDadapter As New eServicii.DataSetJURAMANTTableAdapters.aspnet_UsersTableAdapter
        Dim UserNr As Integer
        Dim NumeUser As String
        If IsNothing(Membership.GetUser().UserName()) = False Then
            NumeUser = Membership.GetUser().UserName()
            UserNr = misIDadapter.GetDataMisID(NumeUser).Rows(0).Item("UserNr")
            Return UserNr
        Else
            Return 0
        End If
    End Function

    Protected Sub Selection_Changed() Handles Calendar1.SelectionChanged
        If Calendar1.SelectedDate < Date.Now() Then
            'UserMsgBox(Me, "Data selectata este anterioara datei curente!")
            LabelMSG.Text = "Data selectată e anterioară celei curente!"
            LabelMSG.Visible = True

        Else
            LabelMSG.Visible = False
        End If
    End Sub
    

    Protected Sub ButtonProgr_Click(sender As Object, e As EventArgs) Handles ButtonProgr.Click
        Response.Redirect("Juramant2.aspx")
    End Sub

    Protected Sub ButtonCertif_Click(sender As Object, e As EventArgs) Handles ButtonCertif.Click
        Response.Redirect("JuramantCertificate.aspx")
    End Sub


    Public Sub UserMsgBox(ByVal F As Object, ByVal sMsg As String)
        Dim sb As New StringBuilder()
        Dim oFormObject As System.Web.UI.Control = Nothing
        Try
            sMsg = sMsg.Replace("'", "\'")
            sMsg = sMsg.Replace(Chr(34), "\" & Chr(34))
            sMsg = sMsg.Replace(vbCrLf, "\n")
            sMsg = "<script language='javascript'>alert('" & sMsg & "');</script>"
            sb = New StringBuilder()
            sb.Append(sMsg)
            For Each oFormObject In F.Controls
                If TypeOf oFormObject Is HtmlForm Then
                    Exit For
                End If
            Next
            oFormObject.Controls.AddAt(oFormObject.Controls.Count, New LiteralControl(sb.ToString()))
        Catch ex As Exception
        End Try
    End Sub
    

End Class

